package com.lmc.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lmc.common.LogInfo;
import com.lmc.common.R;
import com.lmc.pojo.User;
import com.lmc.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
@Slf4j
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 根据用户姓名查询用户账户余额
     *
     * @param name
     * @return
     */
    @LogInfo(describe = "操作用户")
    @GetMapping("/account")
    public R<User> queryByName(@RequestParam String name) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(name), User::getName, name);
        User user = userService.getOne(lqw);
        return R.success(user);
    }

}
